package com.sanjiahantang.ythshopping.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.sanjiahantang.ythshopping.R;
import com.sanjiahantang.ythshopping.activity.me.TypeOrderActivity;
import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;
//    wx91454dc8c8d5c13a
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, ConfigValue.WXAPP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {

        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

            if (resp.errCode == -1) {

            } else if (resp.errCode == -2) {
                Intent intent = new Intent(WXPayEntryActivity.this, TypeOrderActivity.class);
                intent.putExtra("type", 0);
                startActivity(intent);
                finish();
                Toast.makeText(WXPayEntryActivity.this, "支付已取消", Toast.LENGTH_LONG).show();

            } else {
                Intent intent1 = new Intent(WXPayEntryActivity.this, TypeOrderActivity.class);
                intent1.putExtra("type", 1);
                startActivity(intent1);

                Toast.makeText(WXPayEntryActivity.this, "支付成功", Toast.LENGTH_LONG).show();

            }

        }
    }

    private CharSequence getString(String string, String valueOf) {
        // TODO Auto-generated method stub
        return null;
    }
}